# JavaScript continue Statement

JavaScript Statements Reference

## Example

In this example we use a for loop together with the continue statement.

Loop through a block of code, but skip the value of "3":

var text = ""
var i;
for (i = 0; i < 5; i++) {
if (i == 3) {
continue;
}
text += "The number is " + i + "<br>";
}

The result of text will be:

The number is 0
The number is 1
The number is 2
The number is 4
Try it yourself »

More "Try it Yourself" examples below.

## Definition and Usage

The continue statement breaks one iteration (in the loop) if a specified condition occurs, and continues with the next iteration in the loop.

The difference between continue and the break statement, is instead of "jumping out" of a loop, the continue statement "jumps over" one iteration in the loop.

However, when the continue statement is executed, it behaves differently for different types of loops:

- In a while loop, the condition is tested, and if it is true, the loop is executed again
- In a for loop, the increment expression (e.g. i++) is first evaluated, and then the condition is tested to find out if another iteration should be done

The continue statement can also be used with an optional label reference.

Note: The continue statement (with or without a label reference) can only be used inside a loop.

## Browser Support

Statement |  |  |  |  |
--- | --- | --- | --- | --- | ---
continue | Yes | Yes | Yes | Yes | Yes

## Syntax

continue;

Using the optional label reference:

continue labelname;

## Technical Details

JavaScript Version: | 1.0. The label reference was added in JavaScript 1.2

## More Examples

## Example

In this example we use a while loop together with the continue statement.

Loop through a block of code, but skip the value of "3":

var text = "";
var i = 0;
while (i < 5) {
i++;
if (i == 3) {
continue;
}
text += "<br>The number is " + i;
}

The result of text will be:

The number is 1
The number is 2
The number is 4
The number is 5
Try it yourself »

## Example

In this example we use a for loop together with the continue statement.

Loop through an array, but skip the array's element "Saab":

var cars = ["BMW", "Volvo", "Saab", "Ford"];
var text = ""
var i;
for (i = 0; i < cars.length; i++) {
if (cars[i] == "Saab") {
continue;
}
text += cars[i] + "<br>";
}

The result of text will be:

BMW
Volvo
Ford
Try it yourself »

## Example

Using the continue statement with a label reference, to skip a value in a nested for loop:

var text = "";
var i, j;
Loop1: // The first for loop is labeled "Loop1"
for (i = 0; i < 3; i++) {
text += "<br>" + "i = " + i + ", j = ";
Loop2: // The second for loop is labeled "Loop2"
for (j = 10; j < 15; j++) {
if (j == 12) {
continue Loop2;
}
document.getElementById("demo").innerHTML = text += j + " ";
}
}

The result of text will be:

i = 0, j = 10 11 13 14
i = 1, j = 10 11 13 14
i = 2, j = 10 11 13 14
Try it yourself »

## Related Pages

JavaScript Tutorial: JavaScript Break and Continue

JavaScript Tutorial: JavaScript For Loop

JavaScript Tutorial: JavaScript While Loop

JavaScript Tutorial: JavaScript break Statement

JavaScript Reference: JavaScript for Statement

JavaScript Reference: JavaScript while Statement

JavaScript Statements Reference

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples